# -*- coding: utf-8 -*-
from datetime import timedelta
from utils.operators.spark_sql_operator import SparkSqlOperator
from jms.time_sensor.time_after_09_00 import time_after_09_00


oss__oss_tmp_center_detention_detail = SparkSqlOperator(
    task_id='oss__oss_tmp_center_detention_detail',
    task_concurrency=1,
    pool_slots=1,
    master='yarn',
    retries=2,
    execution_timeout = timedelta(minutes=60),
    email=['guoruiling@jtexpress.com','yl_bigdata@yl-scm.com'],
    name='oss__oss_tmp_center_detention_detail_{{ execution_date | date_add(-1) | cst_ds }}',
    sql='jms/oss/oss_tmp_center_detention_detail/execute.hql',
    driver_memory='8G',
    driver_cores=4,
    executor_cores=4,
    executor_memory='6G',
    num_executors=30,
    conf={
        'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
        'spark.shuffle.service.enabled': 'true',  # 动态资源 Shuffle 服务开启
        'spark.dynamicAllocation.maxExecutors': 30,  # 动态资源最大扩容 Executor 数
        'spark.dynamicAllocation.cachedExecutorIdleTimeout': 120,  # 动态资源自动释放闲置 Executor 的超时时间(s)
        'spark.executor.memoryOverhead': '2G',  # 堆外内存
        'spark.hadoop.hive.exec.dynamic.partition.mode': 'nonstrict', # 动态分区
        'spark.hadoop.hive.exec.dynamic.partition': 'true',
        'spark.sql.shuffle.partitions': 360,
        'spark.yarn.maxAppAttempts':1
    },
    hiveconf={'hive.exec.dynamic.partition': 'true',
              'hive.exec.dynamic.partition.mode': 'nonstrict',
              'hive.exec.max.dynamic.partitions.pernode': 200,
              'hive.exec.max.dynamic.partitions': 200
              },
    yarn_queue='pro',
)

oss__oss_tmp_center_detention_detail  << [
    time_after_09_00
]
 